<?php
/*
# $Id: init.php 225 2007-11-22 16:03:18Z james $
#
# Initialises the core system by performing the following tasks:
#	- Include all necessary libraries
#	- Prepare global functions and variables
#
# It does NOT operate on any passed parameters (in particular, $_REQUEST['do'])
# - this is left to the application in order to provide as much freedom from the
# core as possible. The core is only here to provide the code framework, not
# overly-enforce routines on the programmer.
*/

/*
# Ensure this script is called only once by setting a global flag.
# This could easily be achieved by "require_once()"ing this script, but that
# relies on unwavering user-compliance!
*/
if(defined('BUAN_INIT_STARTED')) {
	return 0;
}
define('BUAN_INIT_STARTED', TRUE);

/*
# Enable output buffering (if it's not too late!)
*/
$ini_ob = (int)ini_get('output_buffering');
if($ini_ob<=0) {
	ob_start();
}

/*
# Setup the class auto-loader and other common classes
*/
$cwd = dirname(__FILE__);
include($cwd.'/lib/BuanAutoLoader.php');
include($cwd.'/lib/Config.php');

/*
# Set some global configuration values.
*/
Config::set('timeStarted', microtime(TRUE));
Config::set('core', array(
	/* Directory and URL locations */
	'dir'=>array(
		'controllers'=>$cwd.'/controllers',
		'extensions'=>$cwd.'/extensions',
		'models'=>$cwd.'/models',
		'modelManagers'=>$cwd.'/models/managers',
		'resources'=>$cwd.'/buan-pub',		// Public resources folder
		'views'=>$cwd.'/views'
	),
	'url'=>array(
		'resources'=>'/buan-pub'	// Relative URL public resources folder
	),
	'docRoot'=>$cwd,

	/* Version information */
	'version'=>array(
		'major'=>0,
		'minor'=>2,
		'revision'=>0
	)
));

/*
# Add some class search paths
*/
BuanAutoLoader::addClassPath($cwd.'/lib');
BuanAutoLoader::addClassPath($cwd.'/lib/decorators');
BuanAutoLoader::addClassPath(Config::get('core.dir.models'));
BuanAutoLoader::addClassPath(Config::get('core.dir.modelManagers'));

/*
# Set a flag to indicate that initialisation has completed.
*/
unset($cwd);
define('BUAN_INIT_FINISHED', TRUE);
?>